package com.timerecording.util;

import org.springframework.beans.BeanUtils;
import org.springframework.util.CollectionUtils;

import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
//import java.util.stream.Collections;

/**
 * @author smz41
 * @description: TODO
 * @date 2023/6/20
 */
public class SmartBeanUtil {
    public SmartBeanUtil(){
    }

public static void cpoyProperties(Object source,Object target){
    BeanUtils.copyProperties(source, target);
}

public static <T> T copy(Object source,Class<T> target){
try{
    T newInstance = target.newInstance();
    BeanUtils.copyProperties(source,newInstance);
    return newInstance;
}catch (Exception var3){
throw new RuntimeException(var3);
}
}

public static <T,K> List<K> copyList(List<T> source,Class<K> target){
        return CollectionUtils.isEmpty(source) ? Collections.emptyList() : (List)source.stream().map((e) -> {
             return copy(e,target);
        }).collect(Collectors.toList());

}





}
